/* 
 * Copyright 2013 Sébastien Mouquet.
 * 
 * This file is part of ECovoiturage.
 * 
 * ECovoiturage is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ECovoiturage is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ECovoiturage. If not, see http://www.gnu.org/licenses/.
 */
package com.smouquet.ecovoiturage.ui.page.admin;

import com.smouquet.ecovoiturage.ui.page.AbstractUI;
import com.smouquet.ecovoiturage.ui.page.LoginView;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.Runo;
import org.vaadin.addon.borderlayout.BorderLayout;

/**
 *
 * @author sebastien.mouquet
 */
public class AdminUI extends AbstractUI implements Button.ClickListener
{
    private Button btnDeconnexion;
    

    @Override
    protected void initialize()
    {
        //
        // Layout
        //
        BorderLayout layout = new BorderLayout();
        layout.setMargin(true);
        layout.setSizeFull();
        setContent(layout); 
        
        //
        // Top
        //
        HorizontalLayout layoutTop = new HorizontalLayout();
        layoutTop.setWidth(100, Unit.PERCENTAGE);
        layoutTop.setHeight(100, Unit.PIXELS);
        layout.addComponent(layoutTop, BorderLayout.Constraint.NORTH);
        
        //
        // Top - Title
        //
        VerticalLayout layoutTitle = new VerticalLayout();
        layoutTitle.setSizeFull();
        layoutTop.addComponent(layoutTitle);
        layoutTop.setExpandRatio(layoutTitle, 1);
        
        Label lbTitle = new Label("ECovoiturage");
        lbTitle.setSizeUndefined();
        lbTitle.addStyleName(Runo.LABEL_H1);
        layoutTitle.addComponent(lbTitle);
        layoutTitle.setComponentAlignment(lbTitle, Alignment.BOTTOM_CENTER);
        
        Label lbSubtitle = new Label("Covoiturage en entreprise");
        lbSubtitle.setSizeUndefined();
        layoutTitle.addComponent(lbSubtitle);
        layoutTitle.setComponentAlignment(lbSubtitle, Alignment.TOP_CENTER);
        
        // Top - Blank
        VerticalLayout layoutBlank = new VerticalLayout();
        layoutBlank.setSizeFull();
        layoutTop.addComponent(layoutBlank);
        layoutTop.setExpandRatio(layoutBlank, 2);
        
        //
        // Top - Link
        //
        HorizontalLayout layoutLink = new HorizontalLayout();
        layoutLink.setSizeFull();
        layoutLink.setSpacing(true);
        layoutTop.addComponent(layoutLink);
        layoutTop.setExpandRatio(layoutLink, 1);
        
        btnDeconnexion = new Button("Deconnexion");
        btnDeconnexion.addStyleName(Runo.BUTTON_LINK);
        btnDeconnexion.addClickListener(this);
        layoutLink.addComponent(btnDeconnexion);
        layoutLink.setComponentAlignment(btnDeconnexion, Alignment.BOTTOM_RIGHT);
        
        //
        // Content
        //
        TabSheet tabSheet = new TabSheet();
        tabSheet.setSizeFull();
        layout.addComponent(tabSheet, BorderLayout.Constraint.CENTER);
        
        tabSheet.addTab(new Label(), "Entreprise");
        tabSheet.addTab(new Label(), "Utilisateurs");
    }
    

    @Override
    public void buttonClick(ClickEvent event)
    {
        if(btnDeconnexion.equals(event.getButton()))
        {
            doDeconnexion();
        }
    }
    
    
    private void doDeconnexion()
    {
        getMainNavigator().navigateTo(LoginView.VIEW_NAME);
    }
}
